﻿Option Strict On
Option Explicit On
Option Infer On

Imports System

<Flags()> _
Public Enum MemberModifiers
   ' These values must be explicitly set because this is a flagged (bitwise) enumeration
   None = 0
   [MustOverride] = 1
   [Overrides] = 2
   [Overridable] = 4
   [NotOverridable] = 8
   [Overloads] = 16
   [Shared] = 32
   NewSlot = 64
   [Partial] = 128
End Enum

Namespace VB
   Public Module ModifiersExtensions
      <System.Runtime.CompilerServices.Extension()> _
      Public Function Output(ByVal modifiers As MemberModifiers) As String
         Dim ret As String = String.Empty
         If (modifiers And TemplateSupport.MemberModifiers.Shared) = TemplateSupport.MemberModifiers.Shared Then
            ret &= "Shared "
         End If
         If (modifiers And TemplateSupport.MemberModifiers.MustOverride) = TemplateSupport.MemberModifiers.MustOverride Then
            ret &= "MustOverride "
         End If
         If (modifiers And TemplateSupport.MemberModifiers.Overrides) = TemplateSupport.MemberModifiers.Overrides Then
            ret &= "Overrides"
         End If
         If (modifiers And TemplateSupport.MemberModifiers.Overloads) = TemplateSupport.MemberModifiers.Overloads Or _
               (modifiers And TemplateSupport.MemberModifiers.NewSlot) = TemplateSupport.MemberModifiers.NewSlot Then
            ret &= "Overloads "
         End If
         If (modifiers And TemplateSupport.MemberModifiers.Partial) = TemplateSupport.MemberModifiers.Partial Then
            ret &= "Partial "
         End If
         Return ret.Trim
      End Function
   End Module
End Namespace

Namespace CSharp
   Public Module ModifiersExtensions
      <System.Runtime.CompilerServices.Extension()> _
      Public Function Output(ByVal modifiers As MemberModifiers) As String
         Dim ret As String = String.Empty
         If (modifiers And TemplateSupport.MemberModifiers.MustOverride) = TemplateSupport.MemberModifiers.MustOverride Then
            ret &= "abstract"
         End If
         If (modifiers And TemplateSupport.MemberModifiers.Overrides) = TemplateSupport.MemberModifiers.Overrides Then
            ret &= "override"
         End If
         If (modifiers And TemplateSupport.MemberModifiers.Overloads) = TemplateSupport.MemberModifiers.Overloads Then
            ' Becuase VB is sometimes ambiguous in the use of new slot and overloads, 
            ' this will sometimes be wrong on converted templates. VB programmers 
            ' rarely understand or care (including myself)
            ret &= "new"
         End If
         If (modifiers And TemplateSupport.MemberModifiers.Partial) = TemplateSupport.MemberModifiers.Partial Then
            ret &= "partial"
         End If
         ' Overloads is not needed in C#
         Return ret
      End Function
   End Module
End Namespace
